package view;
 
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import controller.Controladora;
 
@SuppressWarnings("serial")
public class PlotSummary extends JPanel {
	
    PlotStatistics plot;
    private Object[][] data;
    private JTable table;
    private Controladora controladora;
 
    public PlotSummary(Controladora controladora) {
        super(new BorderLayout());
        this.controladora = controladora;
		
		data = new Object[0][7];
		
        table = new JTable(new PlotSummaryModel(data)); 
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
 
        //Add the scroll pane to this' panel.
        add(scrollPane, BorderLayout.CENTER);
        
    }

    /**
     * Actualitza la taula.
     */
	public void updateTable() {
		((PlotSummaryModel)table.getModel()).setData(new Object[controladora.getSessions().size()][7]);
		for (int i = 0; i < controladora.getSessions().size(); i++){
			table.getModel().setValueAt(controladora.getSessions().get(i).getName(), i, 0);
			table.getModel().setValueAt(controladora.getSessions().get(i).getCircuit(), i, 1);
			table.getModel().setValueAt(controladora.getSessions().get(i).getMinTime(), i, 2);
			table.getModel().setValueAt(controladora.getSessions().get(i).getAvgTime(), i, 3);
			table.getModel().setValueAt(controladora.getSessions().get(i).getAvgTopSpeed(), i, 4);
			table.getModel().setValueAt(controladora.getSessions().get(i).getAvgAvgSpeed(), i, 5);
			table.getModel().setValueAt(controladora.getSessions().get(i).getAvgMinSpeed(), i, 6);
    	}
	}

}